import requests


class TestJCLogin(object):
    #     def setup(self):
    #         print("这是每个方法前执行一次")
    #
    #     def teardown_method(self):
    #         print("这是 每个方法后执行一次")
    #
    #     def setup_class(self):
    #         print("所有方法前执行一次")
    #
    #     def teardown_class(self):
    #         print("所有方法后执行一次")

    # 定义方法-登录成功
    def test01_login_success(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "password": "jxz123456!@#", "category": "0"})
        print("登录成功", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 0 == resp.json().get("code")
        assert None is resp.json().get("success")

    # 定义方法-手机号未注册
    def test02_mobile_unregistered(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811797670", "password": "jxz123456!@#", "category": "0"})
        print("手机号未注册", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 1004001001 == resp.json().get("code")
        assert "手机号未注册用户" == resp.json().get("msg")

    # 定义方法-密码错误
    def test03_pwd_error(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "password": "jxz123", "category": "0"})
        print("密码错误", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 1004003000 == resp.json().get("code")
        assert "登录失败，账号密码不正确" == resp.json().get("msg")

    # 定义方法-注册后未审核去登录
    # def test04_mobile_unreviewed(self):
    #     resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
    #                          headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
    #                          json={"mobile": "18554023309", "password": "123456", "category": "0"})
    #     print("注册后未审核去登录", resp.json())
    #     # 断言
    #     assert 200 == resp.status_code
    #     assert 1004014003 == resp.json().get("code")
    #     assert "用户企业资质审核审核中，请联系客服处理" == resp.json().get("msg")
    # 因为现在这个1855的号是已经审核过了的，还得去postman吧账号改为未审核麻烦所以不要了

    # 定义方法-手机号为空
    def test05_mobile_none(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": None, "password": "jxz123456!@#", "category": "0"})
        print("手机号为空", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:手机号不能为空" == resp.json().get("msg")

    # 定义方法-手机号含有字母特殊字符
    def test06_mobile_contain_letters_characters(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796@A!", "password": "jxz123456!@#", "category": "0"})
        print("手机号含有字母特殊字符", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:手机号格式不正确" == resp.json().get("msg")

    # 定义方法-手机号10位
    def test07_mobile_ten(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "1981179670", "password": "jxz123456!@#", "category": "0"})
        print("手机号10位", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:手机号格式不正确" == resp.json().get("msg")

    # 定义方法-手机号12位
    def test08_mobile_twelve(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "198117967055", "password": "jxz123456!@#", "category": "0"})
        print("手机号12位", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:手机号格式不正确" in resp.json().get("msg")

    # 定义方法-密码为空
    def test09_password_none(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "password": None, "category": "0"})
        print("密码为空", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:密码不能为空" == resp.json().get("msg")

    # 定义方法-密码含有字母特殊字符
    def test10_password_contain_letters_characters(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "password": "jxz123456!@#", "category": "0"})
        print("密码含有字母特殊字符", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 0 == resp.json().get("code")
        assert "" == resp.json().get("msg")

    # 定义方法-密码5位
    def test11_password_five(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "password": "jxz12", "category": "0"})
        print("密码5位", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "密码长度为 6-15 位" in resp.json().get("msg")

    # 定义方法-密码16位
    def test12_password_sixteen(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "password": "jxz1234567890123", "category": "0"})
        print("密码16位", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "密码长度为 6-15 位" in resp.json().get("msg")

    # 定义方法-多参abc
    def test13_more_parameter_abc(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "password": "jxz123456!@#", "category": "0", "abc": "123"})
        print("多参abc", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 0 == resp.json().get("code")

    # 定义方法-少参mobile
    def test14_less_parameter_mobile(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"password": "jxz123456!@#", "category": "0"})
        print("少参mobile", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:手机号不能为空" == resp.json().get("msg")

    # 定义方法-无参
    def test15_no_parameter(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={})  # 空字典
        print("无参", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:手机号不能为空" or "请求参数不正确:密码不能为空" == resp.json().get("msg")

    # 定义方法-修改password为abc
    def test16_password_update_abc(self):
        resp = requests.post(url="http://116.62.53.189:48080/app-api/member/auth/login",
                             headers={"Content-Type": "application/json", "Tenant-Id": "1", "Terminal": "20"},
                             json={"mobile": "19811796705", "abc": "jxz123456", "category": "0"})
        print("错误参数", resp.json())
        # 断言
        assert 200 == resp.status_code
        assert 400 == resp.json().get("code")
        assert "请求参数不正确:手机号不能为空" or "请求参数不正确:密码不能为空" == resp.json().get("msg")
